package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.StudentAndExam;

@Repository
public interface StudentAndExamDao extends JpaRepository<StudentAndExam, Integer>, JpaSpecificationExecutor<StudentAndExam> {

	@Query("from StudentAndExam where uniqueCode = ?1")
	List<StudentAndExam> find(String name);

	@Query("from StudentAndExam where uniqueCode like ?1")
	List<StudentAndExam> findLike(String name);

	@Query(value = "select * from StudentAndExam limit ?, ?", nativeQuery = true)
	List<StudentAndExam> findPage(Integer offset, Integer size);

	@Query(value = "select * from StudentAndExam where uniqueCode = ? limit ?, ?", nativeQuery = true)
	List<StudentAndExam> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from StudentAndExam where uniqueCode like ? limit ?, ?", nativeQuery = true)
	List<StudentAndExam> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from StudentAndExam where uniqueCode = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from StudentAndExam where uniqueCode like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from StudentAndExam order by id asc")
	List<StudentAndExam> findAllAsc();
}

